home *** CD-ROM | disk | FTP | other *** search
/ Flash MX Savvy / FlashMX Savvy.iso / pc / MAC / Amapi3D / Amapi3DTrial_Edition / 3SPACE / 3SpaceLib.js < prev    next >
Encoding:
Text File  |  2001-02-20  |  17.4 KB  |  860 lines  |  [AMAS/AMAP]

  1. // -* 3SpaceLib.js *-
  2. //
  3. // Name: 3Space Library
  4. // Description: Core functions for 3Space behaviors
  5. // Author: Frederic Brunel, Mickael Gasrel
  6. // Version: $Id: 3SpaceLib.js,v 1.35 2000/12/29 10:12:02 consumer Exp $
  7. //
  8.  
  9. //
  10. // Global variables
  11. //
  12. var browser  = navigator.appName.toLowerCase () ;
  13. var gPlayer;
  14. var sceneId;
  15.  
  16. var defaultPlayerName = "TSPlayer";
  17. var defaultSceneID = "TSScene";
  18. var init = "0";
  19.  
  20. //
  21. // Library initialization.
  22. //
  23. function TSLibInit(playerName, sceneIdInit)
  24.   if (browser == "netscape") {
  25.     gPlayer = document.embeds[playerName];
  26.   } 
  27.   else {
  28.     if (browser == "microsoft internet explorer") {
  29.       gPlayer = document.all[playerName];
  30.     }
  31.   }
  32.   
  33.   sceneId = sceneIdInit;
  34.  
  35.   // The lib is now initialized
  36.   init = "1";
  37. }
  38.  
  39. var guid = 0;
  40.  
  41. // Utility function:creates a unique name from a basename
  42. function TSMakeUniqID(baseName)
  43. {
  44.   return baseName + "_" + guid++;
  45. }
  46.  
  47. function TSGetSceneId()
  48. {
  49.   return sceneId;
  50. }
  51.  
  52. //
  53. // Nodes management.
  54. //
  55. function TSAppendChild(parentId, nodeId) 
  56. {
  57.   if (init == "0")
  58.     TSLibInit(defaultPlayerName, defaultSceneID);
  59.  
  60.   if (gPlayer != null) {
  61.     gPlayer.TSAppendChild(parentId, nodeId);
  62.   }
  63.   else {
  64.     error ("TSAppendChild", "3Space library not initialized");
  65.   }
  66. }
  67.  
  68. function TSCreateNode(nodeType, nodeId) 
  69. {
  70.   if (init == "0")
  71.     TSLibInit(defaultPlayerName, defaultSceneID);
  72.  
  73.   if (gPlayer != null) {
  74.     gPlayer.TSCreateNode(nodeType, nodeId);
  75.   }
  76.   else {
  77.     error ("TSCreateNode", "3Space library not initialized") ;
  78.   }
  79. }
  80.  
  81. function TSGetAttribute(nodeId, attributeName) 
  82. {
  83.   if (init == "0")
  84.     TSLibInit(defaultPlayerName, defaultSceneID);
  85.  
  86.   if (gPlayer != null) {
  87.     var attributeValue = gPlayer.TSGetAttribute(nodeId, attributeName);
  88.     if (attributeValue == "") {
  89.       error ("TSGetAttribute", "Attribute '" + attributeName + "' not found in the node '" + nodeId + "'") ;
  90.     }
  91.     else {
  92.       return attributeValue ;
  93.     }
  94.   }
  95.   else {
  96.     error ("TSGetAttribute", "3Space library not initialized") ;
  97.   }
  98. }
  99.  
  100. function TSRemoveNode(nodeId)
  101. {
  102.   if (init == "0")
  103.     TSLibInit(defaultPlayerName, defaultSceneID);
  104.  
  105.   if (gPlayer != null) {
  106.     gPlayer.TSRemoveNode (nodeId);
  107.   }
  108.   else {
  109.     error ("TSRemodeNode", "3Space library not initialized") ;
  110.   }  
  111. }
  112.  
  113. function TSSetAttribute(nodeId, attributeName, attributeValue) 
  114. {
  115.   if (init == "0")
  116.     TSLibInit(defaultPlayerName, defaultSceneID);
  117.  
  118.   if (gPlayer != null) {
  119.     gPlayer.TSSetAttribute (nodeId, attributeName, attributeValue) ;
  120.   }
  121.   else {
  122.     error ("TSSetAttribute", "3Space library not initialized") ;
  123.   }
  124. }
  125.  
  126. function TSSetSource(sourceFile, xmlId) 
  127. {
  128.   if (init == "0")
  129.     TSLibInit(defaultPlayerName, defaultSceneID);
  130.  
  131.   if (gPlayer != null) {
  132.     if (browser == "netscape") {
  133.       gPlayer.TSSetSource (sourceFile) ;
  134.     }
  135.     else if (browser == "microsoft internet explorer") {
  136.       gPlayer.XMLID = xmlId ;
  137.     }
  138.   }
  139.   else {
  140.     error ("TSSetSource", "3Space library not initialized") ;
  141.   }
  142. }
  143.  
  144. function TSUpdateNode(nodeId) 
  145. {
  146.   if (init == "0")
  147.     TSLibInit(defaultPlayerName, defaultSceneID);
  148.  
  149.   if (gPlayer != null) {
  150.     gPlayer.TSUpdateNode (nodeId) ;
  151.   }
  152.   else {
  153.     error ("TSUpdateNode", "3Space library not initialized") ;
  154.   }
  155. }
  156.  
  157. function TSUpdateNodeAttribute(nodeId, attributeName, attributeValue)
  158. {
  159.   if (init == "0")
  160.     TSLibInit(defaultPlayerName, defaultSceneID);
  161.  
  162.   if (gPlayer != null) {
  163.     gPlayer.TSUpdateNodeAttribute (nodeId, attributeName, attributeValue) ;
  164.   }
  165.   else {
  166.     error ("TSUpdateNodeAttribute", "3Space library not initialized") ;
  167.   }
  168. }
  169.  
  170. function TSGetExtraParam(nodeId, paramName) 
  171. {
  172.   if (init == "0")
  173.     TSLibInit(defaultPlayerName, defaultSceneID);
  174.  
  175.   if (gPlayer != null) {
  176.       return gPlayer.TSGetExtraParam(nodeId, paramName);
  177.   }
  178.   else {
  179.       error ("TSGetExtraParam", "3Space library not initialized") ;
  180.   }
  181. }
  182.  
  183. function TSSetExtraParam(nodeId, paramName, paramValue) 
  184. {
  185.   if (init == "0")
  186.     TSLibInit(defaultPlayerName, defaultSceneID);
  187.  
  188.   if (gPlayer != null) {
  189.     gPlayer.TSSetExtraParam(nodeId, paramName, paramValue);
  190.   }
  191.   else {
  192.       error ("TSSetExtraParam", "3Space library not initialized") ;
  193.   }
  194. }
  195.  
  196. //
  197. // Miscellaneous.
  198. //
  199. function error (functionName, message)
  200. {
  201.   alert("Error in function " + functionName + " :\n" + message);
  202. }
  203.  
  204. //-----------------------------------------------------------------
  205. // Description: Basic maths
  206. //
  207.  
  208. //
  209. // Conversions
  210. //
  211.  
  212. function TSDegToRad(angleDeg)
  213. {
  214.   return angleDeg * Math.PI / 180.0;
  215. }
  216.  
  217. function TSRadToDeg(angleRad)
  218. {
  219.   return angleRad / Math.PI * 180.0;
  220. }
  221.  
  222. //
  223. // Point
  224. //
  225.  
  226. function TSPoint(x, y, z)
  227. {
  228.   this.x = x;
  229.   this.y = y;
  230.   this.z = z;
  231. }
  232.  
  233. function TSMakePoint(x, y, z)
  234. {
  235.   return new TSPoint(x, y, z);
  236. }
  237.  
  238. function TSMakePointFromString(str)
  239. {
  240.   // Resolves bug on NS
  241.   str = str + '\0';
  242.   var strSplit = str.split(" ");
  243.   return new TSPoint(parseFloat (strSplit[0]), parseFloat (strSplit[1]), parseFloat (strSplit[2]));
  244. }
  245.  
  246. function TSMakeStringFromPoint(pt)
  247. {
  248.   return (pt.x + ' ' + pt.y + ' ' + pt.z);
  249. }
  250.  
  251. function TSPointEqual(p1, p2)
  252. {
  253.   return (TSPointDistance(p1, p2) == 0);
  254. }
  255.  
  256. //
  257. // Point operations
  258. //
  259.  
  260. function TSPointRotateX(pt, angle)
  261. {
  262.   new_x = pt.x
  263.   new_y = (pt.y * Math.cos(angle)) + (pt.z * Math.sin(angle))
  264.   new_z = (pt.z * Math.cos(angle)) - (pt.y * Math.sin(angle))
  265.  
  266.   return new TSPoint(new_x, new_y, new_z)
  267. }
  268.  
  269. function TSPointRotateY(pt, angle)
  270. {
  271.   new_x = (pt.x * Math.cos(angle)) - (pt.z * Math.sin(angle))
  272.   new_y = pt.y
  273.   new_z = (pt.x * Math.sin(angle)) + (pt.z * Math.cos(angle))
  274.  
  275.   return new TSPoint(new_x, new_y, new_z)
  276. }
  277.  
  278. function TSPointRotateZ(pt, angle)
  279. {
  280.   new_x = (pt.x * Math.cos(angle)) + (pt.y * Math.sin(angle))
  281.   new_y = (pt.y * Math.cos(angle)) - (pt.x * Math.sin(angle))
  282.   new_z = pt.z
  283.  
  284.   return new TSPoint(new_x, new_y, new_z)
  285. }
  286.  
  287. function TSPointSphericalRotate(theta, phi)
  288. {
  289.   return TSSphericCoordsToVector(TSMakeSphericCoords(1.,parseFloat(theta),parseFloat(phi)));
  290. }
  291.  
  292. function TSPointNegate(pt)
  293. {
  294.   return TSMakePoint(-parseFloat(pt.x),
  295.              -parseFloat(pt.y),
  296.              -parseFloat(pt.z));
  297. }
  298.  
  299. function TSPointTranslate(pt, x, y, z)
  300. {
  301.   return TSMakePoint(parseFloat(pt.x) + parseFloat(x), 
  302.              parseFloat(pt.y) + parseFloat(y), 
  303.              parseFloat(pt.z) + parseFloat(z));
  304. }
  305.  
  306. function TSPointScale(pt, x, y, z) 
  307. {
  308.   return TSMakePoint(parseFloat(pt.x) * parseFloat(x), 
  309.              parseFloat(pt.y) * parseFloat(y), 
  310.              parseFloat(pt.z) * parseFloat(z));
  311. }
  312.  
  313. function TSPointMultiply(pt, c)
  314. {
  315.   return TSMakePoint(parseFloat(pt.x) * parseFloat(c), 
  316.              parseFloat(pt.y) * parseFloat(c), 
  317.              parseFloat(pt.z) * parseFloat(c));
  318. }
  319.  
  320. function TSPointDistance(pt1, pt2) 
  321. {
  322.   return TSVectorLength(TSMakeVector(pt1, pt2));
  323. }
  324.  
  325. function TSPointInterpolate(pt1, pt2, alpha)
  326. {
  327.   return TSMakePoint(parseFloat(pt1.x) * (1.0 - alpha) + parseFloat(pt2.x) * alpha,
  328.              parseFloat(pt1.y) * (1.0 - alpha) + parseFloat(pt2.y) * alpha,
  329.              parseFloat(pt1.z) * (1.0 - alpha) + parseFloat(pt2.z) * alpha);
  330. }
  331.  
  332. //
  333. // Vector operations
  334. // (The vector structure is a point)
  335. //
  336.  
  337. function TSMakeVector(pt1, pt2)
  338. {
  339.   return TSMakePoint(pt2.x - pt1.x, pt2.y - pt1.y, pt2.z - pt1.z);
  340. }
  341.  
  342. function TSMakeVectorFromString(str)
  343. {
  344.   return TSMakePointFromString(str);
  345. }
  346.  
  347. function TSMakeStringFromVector(v)
  348. {
  349.   return TSMakeStringFromPoint(v);
  350. }
  351.  
  352. function TSVectorMultiply(v, c)
  353. {
  354.   return TSPointMultiply(v, c);
  355. }
  356.  
  357. function TSVectorLength(v)
  358. {
  359.   return Math.sqrt((v.x * v.x) + (v.y * v.y) + (v.z * v.z));
  360. }
  361.  
  362. function TSVectorNormalize(v)
  363. {
  364.   return TSPointMultiply(v, 1 / TSVectorLength(v));
  365. }
  366.  
  367. //
  368. // Bounding box
  369. //
  370.  
  371. function TSBoundingBox(pointMin, pointMax)
  372. {
  373.   this.min = pointMin;
  374.   this.max = pointMax;
  375. }
  376.  
  377. function TSMakeBoundingBox(pointMin, pointMax)
  378. {
  379.   var bbox = new TSBoundingBox(pointMin, pointMax);
  380.  
  381.   // [HACK] Le constructeur n'a pas l'air de fonctionner!! :-(
  382.   bbox.min = pointMin;
  383.   bbox.max = pointMax;
  384.  
  385.   return bbox;
  386. }
  387.  
  388. function TSMakeBoundingBoxFromString(str)
  389. {
  390.   // Resolves bug on NS
  391.   str = str + '\0';
  392.   var strSplit = str.split(" ");
  393.   var min = new TSPoint(strSplit[0], strSplit[1], strSplit[2]);
  394.   var max = new TSPoint(strSplit[3], strSplit[4], strSplit[5]);
  395.  
  396.   return TSMakeBoundingBox(min, max);
  397. }
  398.  
  399. function TSBoundingBoxGetLengthX(bbox)
  400. {
  401.   return (bbox.max.x - bbox.min.x);
  402. }
  403.  
  404. function TSBoundingBoxGetLengthY(bbox)
  405. {
  406.   return (bbox.max.y - bbox.min.y);
  407. }
  408.  
  409. function TSBoundingBoxGetLengthZ(bbox)
  410. {
  411.   return (bbox.max.z - bbox.min.z);
  412. }
  413.  
  414. //
  415. // Color
  416. //
  417.  
  418. function TSColor(r, g, b)
  419. {
  420.   this.r = r;
  421.   this.g = g;
  422.   this.b = b;
  423. }
  424.  
  425. function TSMakeColor(r, g, b)
  426. {
  427.   return new TSColor(r, g, b);
  428. }
  429.  
  430. function TSMakeColorFromString(str)
  431. {
  432.   // Resolves bug on NS
  433.   str = str + '\0';
  434.   strSplit = str.split(" ");
  435.   return new TSColor(strSplit[0], strSplit[1], strSplit[2]);
  436. }
  437.  
  438. function TSMakeStringFromColor(col)
  439. {
  440.   return (col.r + ' ' + col.g + ' ' + col.b);
  441. }
  442.  
  443. //
  444. // Color operations
  445. //
  446.  
  447. function TSColorMultiply(col, c)
  448. {
  449.   return TSMakeColor(parseFloat(col.r) * c, 
  450.                      parseFloat(col.g) * c, 
  451.                      parseFloat(col.b) * c);
  452. }
  453.  
  454. //
  455. // Spherical coordinates
  456. //
  457.  
  458. function TSSphericCoords(rho,theta,phi) 
  459. {
  460.   this.rho   = rho;
  461.   this.theta = theta;
  462.   this.phi   = phi;
  463. }
  464.  
  465. function TSMakeSphericCoords(rho,theta,phi)
  466. {
  467.   return new TSSphericCoords(rho,theta,phi);
  468. }
  469.  
  470. function TSMakeSphericCoordsFromString(str)
  471. {
  472.   // Resolves bug on NS
  473.   str = str + '\0';
  474.   var strSplit = str.split(" ");
  475.   return new TSSphericCoords(strSplit[0], strSplit[1], strSplit[2]);
  476. }
  477.  
  478. function TSMakeStringFromSphericCoords(pt)
  479. {
  480.   return (pt.rho + ' ' + pt.theta + ' ' + pt.phi);
  481. }
  482.  
  483. function TSVectorToSphericCoords(vector) 
  484. {
  485.   var rho,theta,phi;
  486.   rho = TSVectorLength(vector);
  487.  
  488.   vector = TSVectorNormalize(vector);
  489.   
  490.   phi = Math.asin(vector.y) ;
  491.     
  492.   cosPhi = Math.cos(phi);
  493.   if (Math.abs(cosPhi) < 0.00001) {
  494.     cosPhi = 0.00001;
  495.   }
  496.   tmp = vector.z / cosPhi;
  497.   if (tmp <= -1) {
  498.     tmp = -0.99999;
  499.   } else if (tmp >= 1) {
  500.     tmp = 0.99999;
  501.   }        
  502.   theta = Math.acos(tmp);
  503.   if (vector.x < 0) {
  504.     theta = -theta;
  505.   }
  506.   
  507.   return TSMakeSphericCoords(rho, theta, phi);
  508. }
  509.  
  510. function TSSphericCoordsToVector(sphericCoords)
  511. {
  512.   fphi = parseFloat(sphericCoords.phi);
  513.   ftheta = parseFloat(sphericCoords.theta);
  514.  
  515.   new_x = (Math.cos(fphi) * Math.sin(ftheta)) * sphericCoords.rho;
  516.   new_y = (Math.sin(fphi)                   ) * sphericCoords.rho;
  517.   new_z = (Math.cos(fphi) * Math.cos(ftheta)) * sphericCoords.rho;
  518.   
  519.   return TSMakePoint(new_x, new_y, new_z);
  520. }
  521.  
  522.  
  523. //-----------------------------------------------------------------
  524. // Description: Functions for accessing and building 3Space objects
  525. //
  526.  
  527. function TSMakeSolid(id, fixed, position)
  528. {
  529.   TSCreateNode("Solid", id);
  530.  
  531.   TSSetAttribute(id, 'fixed', fixed);
  532.   TSSetAttribute(id, 'position', position);
  533. }
  534.  
  535. function TSDropSolid(id)
  536. {
  537.   TSUpdateNodeAttribute(id, 'fixed', '0');
  538. }
  539.  
  540. function TSFreezeSolid(id)
  541. {
  542.   TSUpdateNodeAttribute(id, 'fixed', '1');
  543. }
  544.  
  545. function TSSolidGetPosition(solidName)
  546. {
  547.   return TSMakePointFromString(TSGetAttribute(solidName, 'position'));
  548. }
  549.  
  550. function TSSolidSetPosition(solidName, position)
  551. {
  552.   TSUpdateNodeAttribute(solidName, 'position', position);
  553. }
  554.  
  555. function TSSolidGetMass(solidName)
  556. {
  557.   return parseFloat (TSGetAttribute(solidName, 'mass'));
  558. }
  559.  
  560. function TSSolidGetBoundingBox(solidName)
  561. {
  562.   return TSMakeBoundingBoxFromString(TSGetAttribute(solidName, 'boundingBox'));
  563. }
  564.  
  565. function TSSolidGetLengthX(solidName)
  566. {
  567.   return TSBoundingBoxGetLengthX(TSSolidGetBoundingBox(solidName));
  568. }
  569.  
  570. function TSSolidGetLengthY(solidName)
  571. {
  572.   return TSBoundingBoxGetLengthY(TSSolidGetBoundingBox(solidName));
  573. }
  574.  
  575. function TSSolidGetLengthZ(solidName)
  576. {
  577.   return TSBoundingBoxGetLengthZ(TSSolidGetBoundingBox(solidName));
  578. }
  579.  
  580. function TSSolidGetMaxLength(solidName)
  581. {
  582.   var bbox = TSSolidGetBoundingBox(solidName);
  583.   var max = 0;
  584.  
  585.   if (TSBoundingBoxGetLengthX(bbox) > max)
  586.     max = TSBoundingBoxGetLengthX(bbox);
  587.  
  588.   if (TSBoundingBoxGetLengthY(bbox) > max)
  589.     max = TSBoundingBoxGetLengthY(bbox);
  590.  
  591.   if (TSBoundingBoxGetLengthZ(bbox) > max)
  592.     max = TSBoundingBoxGetLengthZ(bbox);
  593.  
  594.   return max;
  595. }
  596.  
  597. //
  598. // Geometry
  599. //
  600.  
  601. function TSMakeBlock(id, color, lengthX, lengthY, lengthZ)
  602. {
  603.   TSCreateNode("GeomBlock", id);
  604.  
  605.   TSSetAttribute(id, 'color', color);
  606.   TSSetAttribute(id, 'lengthX', lengthX);
  607.   TSSetAttribute(id, 'lengthY', lengthY);
  608.   TSSetAttribute(id, 'lengthZ', lengthZ);
  609. }
  610.  
  611. function TSMakeCone(id, length, radius, color)
  612. {
  613.   TSCreateNode("GeomCone", id);
  614.  
  615.   TSSetAttribute(id, 'color', color);
  616.   TSSetAttribute(id, 'length', length);
  617.   TSSetAttribute(id, 'radius', radius);
  618. }
  619.  
  620. function TSMakeCube(id, length, color)
  621. {
  622.   TSCreateNode("GeomCube", id);
  623.  
  624.   TSSetAttribute(id, 'color', color);
  625.   TSSetAttribute(id, 'length', length);
  626. }
  627.  
  628. function TSMakeCylinder(id, length, radius, color)
  629. {
  630.   TSCreateNode("GeomCylinder", id);
  631.  
  632.   TSSetAttribute(id, 'color', color);
  633.   TSSetAttribute(id, 'length', length);
  634.   TSSetAttribute(id, 'radius', radius);
  635. }
  636.  
  637. function TSMakePlan(id, length, width, color)
  638. {
  639.   TSCreateNode("GeomPlan", id);
  640.  
  641.   TSSetAttribute(id, 'color', color);
  642.   TSSetAttribute(id, 'length', length);
  643.   TSSetAttribute(id, 'width', width);
  644. }
  645.  
  646. function TSMakeSphere(id, radius, color)
  647. {
  648.   TSCreateNode("GeomSphere", id);
  649.  
  650.   TSMsphere.setAttribute(id, 'color', color);
  651.   TSMsphere.setAttribute(id, 'radius', radius);
  652. }
  653.  
  654. function TSMakeText(id, text, size, color)
  655. {
  656.   TSCreateNode("GeomText", id);
  657.  
  658.   TSSetAttribute(id, 'color', color);
  659.   TSSetAttribute(id, 'text', text);
  660.   TSSetAttribute(id, 'size', size);
  661. }
  662.  
  663. function TSMakeGeomURL(id, url, name)
  664. {
  665.   TSCreateNode("GeomURL", id);
  666.  
  667.   TSSetAttribute(id, 'url', url);
  668.   if (name != "")
  669.     TSSetAttribute(id, 'name', name);
  670. }
  671.  
  672. //
  673. // Collision volumes
  674. //
  675.  
  676. function TSMakeVolBounding(id, type)
  677. {
  678.   TSCreateNode("VolBounding", id);
  679.  
  680.   TSSetAttribute(id, 'boundingType', type);
  681. }
  682.  
  683. //
  684. // Light
  685. //
  686.  
  687. function TSMakeSolidPointLight(id, position, color, state)
  688. {
  689.   TSCreateNode("SolidPointLight", id);
  690.  
  691.   TSSetAttribute(id,'fixed', '1');
  692.   TSSetAttribute(id,'position', position);
  693.   TSSetAttribute(id,'color', color);
  694.   TSSetAttribute(id,'state', state);
  695. }
  696.  
  697. function TSMakeSolidSpotLight(id, position, direction, cutOffAngle, dropOffAngle, color, state)
  698. {
  699.   TSCreateNode("SolidSpotLight", id);
  700.  
  701.   TSSetAttribute(id,'fixed', '1');
  702.   TSSetAttribute(id,'position', position);
  703.   TSSetAttribute(id,'direction', direction);
  704.   TSSetAttribute(id,'cutOffAngle', cutOffAngle);
  705.   TSSetAttribute(id,'dropOffAngle', dropOffAngle);
  706.   TSSetAttribute(id,'color', color);
  707.   TSSetAttribute(id,'state', state);
  708. }
  709.  
  710. //
  711. // Camera
  712. //
  713.  
  714. function TSCameraGetPosition(id)
  715. {
  716.   return TSSolidGetPosition(id);
  717. }
  718.  
  719. function TSCameraGetTargetPosition(id)
  720. {
  721.   return TSMakePointFromString(TSGetAttribute(id, 'targetPoint'));
  722. }
  723.  
  724. function TSCameraLookAt(id, targetPoint)
  725. {
  726.   TSUpdateNodeAttribute(id, 'targetPoint', targetPoint)
  727. }
  728.  
  729. function TSCameraLookAtSolid(id, targetID)
  730. {
  731.   TSUpdateNodeAttribute(id, 'target', targetID);
  732. }
  733.  
  734. function TSCameraGetLookAtVector(id)
  735. {
  736.   return TSMakeVector(TSCameraGetPosition(id), TSCameraGetTargetPosition(id));
  737. }
  738.  
  739. //
  740. // Particle systems
  741. //
  742.  
  743. function TSMakeParticleSystem(id,
  744.                   textureFile,
  745.                   emitterShape,
  746.                   position, 
  747.                   rotation, 
  748.                   yawVariation, 
  749.                   pitchVariation,
  750.                   initialColor,
  751.                   endColor,
  752.                   initialSize,
  753.                   endSize,
  754.                   speed,
  755.                   speedVariation,
  756.                   lifeSpan,
  757.                   lifeSpanVariation)
  758. {
  759.   TSCreateNode("ParticleSystem",id);
  760.  
  761.   TSSetAttribute(id, 'particleTexture', textureFile);
  762.   TSSetAttribute(id, 'emitterShape', emitterShape);
  763.   TSSetAttribute(id, 'position', position);
  764.   TSSetAttribute(id, 'rotation', rotation);
  765.   TSSetAttribute(id, 'yawVariation', yawVariation);
  766.   TSSetAttribute(id, 'pitchVariation', pitchVariation);
  767.   TSSetAttribute(id, 'initialColor', initialColor);
  768.   TSSetAttribute(id, 'endColor', endColor);
  769.   TSSetAttribute(id, 'initialSize', initialSize);
  770.   TSSetAttribute(id, 'endSize', endSize);
  771.   TSSetAttribute(id, 'speed', speed);
  772.   TSSetAttribute(id, 'speedVariation', speedVariation);
  773.   TSSetAttribute(id, 'lifeSpan', lifeSpan);
  774.   TSSetAttribute(id, 'lifeSpanVariation', lifeSpanVariation);
  775. }
  776.  
  777. //
  778. // Forces
  779. //
  780.  
  781. function TSMakeDampingSolidForce(id, angular, linear)
  782. {
  783.   TSCreateNode("DampingSolidForce", id);
  784.  
  785.   TSSetAttribute(id, 'angular', angular);
  786.   TSSetAttribute(id, 'linear', linear);
  787. }
  788.  
  789. function TSMakeSpringForce(id, constant, damping, point, target)
  790. {
  791.   TSCreateNode("SpringForce", id);
  792.  
  793.   TSSetAttribute(id, 'constant', constant);
  794.   TSSetAttribute(id, 'damping', damping);
  795.   TSSetAttribute(id, 'point', point);
  796.   TSSetAttribute(id, 'target', target);
  797. }
  798.  
  799. function TSMakeDragForce(id, intensity, dragPoint, targetPoint)
  800. {
  801.   TSCreateNode("DragForce", id);
  802.  
  803.   TSSetAttribute(id, 'intensity', intensity);
  804.   TSSetAttribute(id, 'dragPoint', dragPoint);
  805.   TSSetAttribute(id, 'targetPoint', targetPoint);
  806. }
  807.  
  808. function TSMakeShootForce(id, direction, intensity, point)
  809. {
  810.   TSCreateNode("ShootForce", id);
  811.  
  812.   TSSetAttribute(id, 'direction', direction);
  813.   TSSetAttribute(id, 'intensity', intensity);
  814.   TSSetAttribute(id, 'point', point);
  815. }
  816.  
  817. //
  818. // Links
  819. //
  820.  
  821. function TSMakeAxisLink(id, axis, point, target)
  822. {
  823.   TSCreateNode("AxisLink", id);
  824.  
  825.   TSSetAttribute(id, 'axis', axis);
  826.   TSSetAttribute(id, 'point', point);
  827.   TSSetAttribute(id, 'target', target);
  828. }
  829.  
  830. function TSMakeCylindricalLink(id, axis, point, target)
  831. {
  832.   TSCreateNode("CylindricalLink", id);
  833.  
  834.   TSSetAttribute(id, 'axis', axis);
  835.   TSSetAttribute(id, 'point', point);
  836.   TSSetAttribute(id, 'target', target);
  837. }
  838.  
  839. function TSMakeSphericalLink(id, point, target)
  840. {
  841.   TSCreateNode("SphericalLink", id);
  842.  
  843.   TSSetAttribute(id,'point', point);
  844.   TSSetAttribute(id,'target', target);
  845. }
  846.  
  847. //
  848. // Events
  849. //
  850.  
  851. function TSMakeTimerEvent(id, at, every, handler)
  852. {
  853.   TSCreateNode("TimerEvent", id);
  854.   
  855.   TSSetAttribute(id, 'at', at);
  856.   TSSetAttribute(id, 'every', every);
  857.   TSSetAttribute(id, 'handler', handler);
  858. }
  859.